@extends('layout/default')

@section('content')
<div class="container ">
    <form action="{{URL::to('pay/recharge')}}" method="post" >
        <input type="hidden" name="COCost" value="10">
        <input type="hidden" name="_token" value="{{
        csrf_token()}}">
        <div class="row" style="margin-top: 1em">

                 <div class="col-xs-4 recharge-cost">
                    <span class="btn btn-default" type="button" value="0.01">测试1分钱</span>
                </div>
                <div class="col-xs-4 recharge-cost">
                    <span class="btn btn-default btn-primary" type="button" value="10">10元</span>
                </div>
                <div class="col-xs-4 recharge-cost">
                    <span class="btn btn-default" type="button"  value="20">20元</span>
                </div>
                <div class="col-xs-4 recharge-cost">
                    <span class="btn btn-default" type="button"  value="50">50元</span>
                </div>


                <div class="col-xs-4 recharge-cost">
                     <span class="btn btn-default" type="button" value="100">100元</span>
                 </div>
                 <div class="col-xs-4 recharge-cost">
                     <span class="btn btn-default" type="button" value="200">200元</span>
                 </div>
                 <div class="col-xs-4 recharge-cost">
                     <span class="btn btn-default" type="button" value="500">500元</span>
                 </div>
                 <div class="col-xs-4 recharge-cost">
                      <span class="btn btn-default" type="button" value="1000">1000元</span>
                 </div>

         </div>
         <div class="row">
            <div class="clo-xs-12" style="padding: 15px;margin-top: 5em">
                <input class=" btn btn-primary" type="submit" value="充值" style="width:100%"/>

            </div>

         </div>

    </form>
</div>

@endsection

@section('scripts')
    <script>
    $(function(){
        $('.recharge-cost').click(function(){

            $(this).children('span').addClass('btn-primary');
            $(this).siblings('div').children('span').removeClass('btn-primary')
            $('input[name="COCost"]').val($(this).children('span').attr('value'))
        })
    })
    @if(isset($jsApiParameters)&&isset($order_id))
            callpay()
            //调用微信JS api 支付
            function jsApiCall()
            {
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest',
                    <?php echo $jsApiParameters; ?>,
                    function(res){
                        //WeixinJSBridge.log(res.err_msg);
                        //alert(res.err_msg);
                        if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                            $.ajax({
                                type:'POST',
                                url:"{{URL::to('pay/return_call')}}",
                                data:{order_id:'{{$order_id}}',_token:'{{csrf_token()}}'},
                                success:function(data){
                                    alert(data)
                                }
                            })
                        }
                    }
                );
            }

            function callpay()
            {
                if (typeof WeixinJSBridge == "undefined"){
                    if( document.addEventListener ){
                        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                    }else if (document.attachEvent){
                        document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                    }
                }else{
                    jsApiCall();
                }
            }
    @endif


    </script>
@endsection
